#include <iostream>
#include <map>
#include <cmath>

using namespace std;

map<string, int> english_to_digit = {
    {"zero", 0},
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9}
};

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); ++i) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int process_input(string words[3], int len) {
    string digits;

    for (int i = 0; i < len; ++i) {
        if (english_to_digit.find(words[i]) == english_to_digit.end())
            return -1;
        digits += to_string(english_to_digit[words[i]]);
    }

    int number = stoi(digits);
    
    if(( len == 2 && (number < 10 || number > 99) ) || ( len == 3 && (number < 100 || number > 999)) ) {
        return -1;
    }

    int lower = number, upper = number;

    while (true) {
        if (is_prime(lower)) {
            return lower;
        }
        if (is_prime(upper)) {
            return upper;
        }
        --lower;
        ++upper;
    }

    return -1;
}

int main() {
    string words[3];
    
    int len = 0;
    for (int i = 0; i < 3; ++i) {
        if(cin >> words[i]) len++;
        if(getchar() == '\n') break;
    }

    int result = process_input(words, len);
    
    if (result == -1)
        cout << "Wrong input" << endl;
    else
        cout << result << endl;
    
    return 0;
}













